function encrypt(str){
	return $.md5($.md5(str));
}

function success(title, msg){
	callSwal(title, msg, "success");
}

function error(title, msg){
	callSwal(title, msg, "error");
}

function warning(title, msg){
	callSwal(title, msg, "warning");
}

function customAlert(title, msg, img){
	swal({
		title: title,
		text: msg,
		imageUrl: img,
		showCancelButton: false,
		confirmButtonClass: "btn-primary",
		confirmButtonText: "确 定",
		closeOnConfirm: true
	});
}

function confirm(title, msg, type, callback){
 	swal({
		title: title,
		text: msg,
		type: type,
		showCancelButton: true,
		confirmButtonClass: "btn-primary",
		confirmButtonText: "确 定",
		cancelButtonText: "取 消",
		closeOnConfirm: true,
		closeOnCancel: true
	}, callback);
}

function callSwal(title, msg, type){
	swal({
		title: title,
		text: msg,
		type: type,
		showCancelButton: false,
		confirmButtonClass: "btn-primary",
		confirmButtonText: "确 定",
		closeOnConfirm: true
	});
}

function addEnterListener(callback){
	$(document).bind("keydown", function(event){
		if(event.keyCode == 13){
			callback(event);
		}
	});
}

function removeEnterListener(){
	$(document).unbind("keydown");
}

function truncateText(text, maxLength)
{
	if(text.length > maxLength){
		return text.substring(0, maxLength) + "...";
	}else{
		return text;
	}
}

function isChinese(temp)
{
	var re = /[^\u4e00-\u9fa5]/;
	if(re.test(temp)) return false;
	return true;
}

function textNum(str)
{
	var arr = str.split("");
	var count = 0;
	$.each(arr, function(index, item){
		if(isChinese(item)){
			count++;
		}else{
			count += 0.5;
		}
	});
	return count;
}

template.helper("truncateText", truncateText);
template.helper("noSecond", noSecond);

$(".dataList .thumbnail").on("mouseover", function(){
	$(this).css("border", "solid 1px #67bfe6");
});
$(".dataList .thumbnail").on("mouseout", function(){
	$(this).css("border", "solid 1px #ddd");
});

function noSecond(str){
	return moment(str).format("YYYY-MM-DD hh:mm");
}


$("#search").bind("click", function(){
	var type = getSearchType();
	var keyWord = $("#keyWord").val().trim();
	if(keyWord == "") return;
	window.location.href="/tyw/public/search/search_list?type=" + type + "&keyWord=" + keyWord;
})